#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
from collections import Counter
class Person(object):
    """
    返回具有给定名称的 Person 对象
    """

    def __init__(self, name,grade):
        self.name = name
        self.grade = grade.upper()

    def get_details(self):
        """
        返回包含人名的字符串
        """
        return self.name
    def get_grade(self):
        return self.grade

class Student(Person):
    """
    返回 Student 对象，采用 name, branch, year 3 个参数
    """

    def __init__(self, name,grade, branch, year):
        Person.__init__(self, name,grade)
        self.branch = branch
        self.year = year

    def get_details(self):
        """
        返回包含学生具体信息的字符串
        """
        return "{} studies {} and is in {} year.".format(self.name, self.branch, self.year)
    def get_grade(self):
        c = Counter(self.grade)
        print("Pass: {}, Fail: {}".format(c['A']+c['B']+c['C'],c['D']))
class Teacher(Person):
    """
    返回 Teacher 对象，采用字符串列表作为参数
    """
    def __init__(self, name,grade, papers):
        Person.__init__(self, name,grade)
        self.papers = papers

    def get_details(self):
        return "{} teaches {}".format(self.name, ','.join(self.papers))
    def get_grade(self):
        s = []
        c = Counter(self.grade)
        cm = c.most_common(4)
        for x,y in cm :
            s.append("{}: {}".format(x,y))
        print(', '.join(s))


if __name__ == '__main__':
    if len(sys.argv) < 3:
        sys.exit(-1)
    if sys.argv[1] == 'teacher':
        th = Teacher('tom',sys.argv[2],['c','c++'])
        th.get_grade()
    elif sys.argv[1] == 'student':
        st =Student('jack',sys.argv[2],'xxx',2020)
        st.get_grade()